package com.xingu.xg.handler;

import com.xingu.xg.common.consts.ComCodeMsg;
import com.xingu.xg.common.consts.ComRT;
import com.xingu.xg.common.consts.ComResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ComResult defaultResultExceptionHandler(RuntimeException e) {
        return ComRT.fail(ComCodeMsg.BUSINESS_ERROR, e.getMessage());
    }
}
